package com.ruoyi.whc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whc.domain.Nearman;
import com.ruoyi.whc.service.INearmanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 密接人员记录Controller
 * 
 * @author whc
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/whc/nearman")
public class NearmanController extends BaseController
{
    @Autowired
    private INearmanService nearmanService;

    /**
     * 查询密接人员记录列表
     */
    @PreAuthorize("@ss.hasPermi('whc:nearman:list')")
    @GetMapping("/list")
    public TableDataInfo list(Nearman nearman)
    {
        startPage();
        List<Nearman> list = nearmanService.selectNearmanList(nearman);
        return getDataTable(list);
    }

    /**
     * 导出密接人员记录列表
     */
    @PreAuthorize("@ss.hasPermi('whc:nearman:export')")
    @Log(title = "密接人员记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Nearman nearman)
    {
        List<Nearman> list = nearmanService.selectNearmanList(nearman);
        ExcelUtil<Nearman> util = new ExcelUtil<Nearman>(Nearman.class);
        util.exportExcel(response, list, "密接人员记录数据");
    }

    /**
     * 获取密接人员记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('whc:nearman:query')")
    @GetMapping(value = "/{nmid}")
    public AjaxResult getInfo(@PathVariable("nmid") Long nmid)
    {
        return AjaxResult.success(nearmanService.selectNearmanByNmid(nmid));
    }

    /**
     * 新增密接人员记录
     */
    @PreAuthorize("@ss.hasPermi('whc:nearman:add')")
    @Log(title = "密接人员记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Nearman nearman)
    {
        return toAjax(nearmanService.insertNearman(nearman));
    }

    /**
     * 修改密接人员记录
     */
    @PreAuthorize("@ss.hasPermi('whc:nearman:edit')")
    @Log(title = "密接人员记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Nearman nearman)
    {
        return toAjax(nearmanService.updateNearman(nearman));
    }

    /**
     * 删除密接人员记录
     */
    @PreAuthorize("@ss.hasPermi('whc:nearman:remove')")
    @Log(title = "密接人员记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nmids}")
    public AjaxResult remove(@PathVariable Long[] nmids)
    {
        return toAjax(nearmanService.deleteNearmanByNmids(nmids));
    }
}
